FROM node:lts-alpine3.14

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
    apk add --update bash && \
    apk add --virtual temppkg &&  \
    apk del temppkg && \
    rm -rf /tmp/* /var/tmp/* /var/cache/apk/* /var/cache/distfiles/* && \
    npm install -g cnpm --registry=https://registry.npmmirror.com && \
    cnpm install http-server -g

ENV VENUS_DIR /venus
ENV VENUS_INITIALIZED_MARK $VENUS_DIR/patched
# VENUS_CMS_ADMIN_PORT can't be changed due to sucked vue static configuration
ENV VENUS_CMS_ADMIN_PORT=9001
ENV VENUS_CMS_ADMIN_VUE_PORT=9002
ENV VENUS_CMS_HOST=127.0.0.1
ENV VENUS_CMS_ADMIN_URL=http://www.conerd.cn

ARG LIVENESS_PROBE
RUN addgroup -S venus && adduser -S venus -G venus && \
    mkdir $VENUS_DIR && \
    chown venus:venus $VENUS_DIR && \
    echo "$LIVENESS_PROBE" > $VENUS_DIR/liveness_probe.sh && \
    chmod a+x $VENUS_DIR/liveness_probe.sh && \
    chown venus:venus $VENUS_DIR/liveness_probe.sh

USER venus:venus
COPY --chown=venus:venus ./dist $VENUS_DIR/dist
COPY --chown=venus:venus ./docker/version $VENUS_DIR/version
COPY --chown=venus:venus ./docker/docker-entrypoint.sh $VENUS_DIR/docker-entrypoint.sh

# initilization for the first time
ENTRYPOINT ["/venus/docker-entrypoint.sh"]

CMD ["cd ${VENUS_DIR} && http-server ./dist -p ${VENUS_CMS_ADMIN_VUE_PORT}"]
